package top.codedance.iotp.loadblance.calgorithm;

import top.codedance.iotp.common.entity.NetworkEntity;
import top.codedance.iotp.common.entity.RegistServerMeta;

import java.util.*;

public class CWeight extends CAdapter {
    @Override
    public NetworkEntity execute(List<RegistServerMeta> rsms) {
        Set<RegistServerMeta> sorts = new TreeSet<>((i1, i2) -> i1.getWeight() > i2.getWeight() ? -1 : 1); //从大到小
        for(RegistServerMeta rsm : rsms){
            sorts.add(rsm);
        }
        NetworkEntity ne = null;
        Iterator<RegistServerMeta> iterator = rsms.iterator();
        if(iterator.hasNext()){
            RegistServerMeta rsm = iterator.next();
            ne = new NetworkEntity(rsm.getBindIp(), rsm.getTcpPort());
        }
        return ne;
    }
}
